﻿Shader "Custom/TestShader16"
{
    Properties
    {
        _MainTex("Base (RGB)", 2D) = "white" {}
        _Brightness("Brightness", Float) = 1
        _Saturation("Saturation", Float) = 1
        _Contrast("Contrast", Float) = 1
    }
	SubShader
	{
		Pass
		{
            ZWrite Off
            Cull Off
            ZTest Always

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"

			struct v2f
			{
				float4 pos : SV_POSITION;
				float2 uv : TEXCOORD0;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
            float _Brightness;
            float _Saturation;
            float _Contrast;
			
			v2f vert (appdata_img v)
			{
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv = v.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw;
                return o;
			}
			
			fixed4 frag (v2f i) : SV_Target
			{
                //纹理颜色
                fixed4 texColor = tex2D(_MainTex, i.uv);

                //亮度
                fixed3 finalColor = texColor.rgb * _Brightness;

                //饱和度
                fixed3 gray = fixed3(0.2125, 0.7154, 0.0721);
                fixed luminance = dot(gray, texColor.rgb);
                fixed3 luminanceColor = fixed3(luminance, luminance, luminance);
                finalColor = lerp(luminanceColor, finalColor, _Saturation);

                //对比度
                fixed3 avgColor = fixed3(0.5, 0.5, 0.5);
                finalColor = lerp(avgColor, finalColor, _Contrast);
                return fixed4(finalColor, 1); 
			}
			ENDCG
		}
	}
    Fallback Off
}
